/*
 * @Author: shiguo
 * @Date: 2022-04-25 17:57:29
 * @LastEditors: shiguo
 * @LastEditTime: 2022-10-24 16:08:50
 * @FilePath: /@aks-dev/easyui/android/src/main/java/com/easyui/RNEasyuiModule.java
 */

package com.easyui;

import android.content.Intent;

import androidx.core.app.ActivityCompat;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import android.os.Build;

public class RNEasyuiModule extends ReactContextBaseJavaModule {

    private final ReactApplicationContext context;

    public RNEasyuiModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.context = reactContext;
    }

    @Override
    public String getName() {
        return "RNEasyui";
    }


    @ReactMethod
    public void getDeviceBrand(Promise promise) {
      promise.resolve( Build.BRAND+ Build.MODEL);
    }

    @Deprecated
    @ReactMethod
    public void getStatusBarHeight(final Promise promise) {

//    int status_bar_height = context.getResources().getDimensionPixelSize(context.getResources().getIdentifier("status_bar_height", "dimen", "android"));
//    promise.resolve(status_bar_height);
        int result = 0;
        int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resId > 0) {
            result = context.getResources().getDimensionPixelSize(resId);
        }
        promise.resolve(result);

    }





    @Deprecated
    @ReactMethod
    public void getNavigationBarHeight(final Promise promise) {

//    int navigation_bar_height = context.getResources().getDimensionPixelSize(context.getResources().getIdentifier("navigation_bar_height", "dimen", "android"));
//    promise.resolve(navigation_bar_height);

        int resourceId = 0;
        int rid = context.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
        if (rid != 0) {
            resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
            int result = context.getResources().getDimensionPixelSize(resourceId);
            promise.resolve(result);
        } else {
            promise.resolve(0);
        }
    }


    @ReactMethod
    public void gotoDesktop() {
        //启动一个意图,回到桌面
        Intent desktop = new Intent(Intent.ACTION_MAIN);
        desktop.addCategory(Intent.CATEGORY_HOME);
        ActivityCompat.startActivity(getCurrentActivity(), desktop, null);
    }
}